package com.suixinsanren.design.template.demo04;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public abstract class CaffeineBeverage {

    public void prepareRecipe() {
        boilWater();
        brew();
        pourInCup();
        if (customerWantsCondiments()) {
            addCondiments();
        }
    }

    protected void boilWater() {
        System.out.println("烧开水");
    }

    protected abstract void brew();

    protected void pourInCup() {
        System.out.println("倒入杯中");
    }

    protected abstract void addCondiments();

    protected boolean customerWantsCondiments() {
        System.out.println("请问是否需加料？");
        return userInput().startsWith("yes");
    }

    protected String userInput() {
        String answer = null;
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        try {
            answer = bufferedReader.readLine();
        } catch (IOException e) {
            System.out.println("获取用户输入信息失败");
        }
        return answer == null ? "no" : answer;
    }
}
